//
//  TrimFromTo.swift
//  SwiftUIAnimation
//
//  Created by 李煜 on 2024/8/20.
//

import SwiftUI

struct TrimFromTo: View {
  var body: some View {
    VStack {
      Path { path in
        path.addLines([
          .init(x: 2, y: 1),
          .init(x: 1, y: 0),
          .init(x: 0, y: 1),
          .init(x: 1, y: 2),
          .init(x: 3, y: 0),
          .init(x: 4, y: 1),
          .init(x: 3, y: 2),
          .init(x: 2, y: 1),
        ])
      }

      .trim(from: 0.25, to: 1.0)
      .scale(50, anchor: .topLeading)
      .stroke(Color.black, lineWidth: 3)

      // 360°*0.25 = 90°     90°~270° trimfrom:to从路径0.25处绘制到0.75处
      RoundedRectangle(cornerRadius: 25)
        .trim(from: 0.25, to: 0.75)
        .stroke(Color.blue, lineWidth: 4)
    }

    .padding(20)
    .background(Color(.systemGray5))
  }
}

#Preview {
  TrimFromTo()
}
